#!/bin/bash

# shellcheck source=meta-facebook/recipes-fb/obmc_functions/files/fb-common-functions
source /usr/libexec/fb-common-functions
# shellcheck source=meta-facebook/meta-santabarbara/recipes-phosphor/state/phosphor-state-manager/power-cmd
source /usr/libexec/phosphor-state-manager/power-cmd

post_end_init() {
  if [ "$(get_gpio BIOS_POST_CMPLT)" -eq 0 ]; then
     busctl set-property xyz.openbmc_project.State.Host0 /xyz/openbmc_project/state/host0 \
     xyz.openbmc_project.State.OperatingSystem.Status OperatingSystemState s \
     xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Standby;
  else
     busctl set-property xyz.openbmc_project.State.Host0 \
     /xyz/openbmc_project/state/host0 xyz.openbmc_project.State.OperatingSystem.Status OperatingSystemState s \
     xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive;
  fi
}

# SGPIO Out Bit-83
set_gpio CPU0_SYS_RESET_N 1

# SGPIO Out Bit-85
set_gpio RST_CPU0_KBRST_N 1

# SGPIO Out Bit-101
set_gpio SCM_USB_SEL 0

# SGPIO Out Bit-81
set_gpio BMC_SGPIO_READY 1

# Initial host state
post_end_init

exit 0
